package com.org.core.dao;

import java.sql.Connection;
import java.sql.SQLException;

import com.org.core.datasource.DbcpMysqlDataSource;

public class Transaction {
	private Connection conn = null;
	
	public Connection getConnection(){
		if(this.conn == null) {
			this.conn = DbcpMysqlDataSource.getInstance().getConnection();
		}
		return this.conn;
	}
	
	public Connection getConnectionBak(){
		if(this.conn == null) {
			this.conn = DbcpMysqlDataSource.getInstance().getConnectionBak();
		}
		return this.conn;
	}
	
	public void rollback(){
		try {
			this.conn.rollback();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				this.conn.close();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		}
	}
	
	public void commit() {
		try {
			this.conn.commit();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				this.conn.close();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		}
	}
	
	public void close() {
		try {
			this.conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
